<?php
declare (strict_types = 1);

namespace app\admin\validate;

use think\Validate;

class Admins extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'username' => 'require|alphaNum|max:20',
        'password' => 'require|alphaDash|length:6,20',
        'password2' => 'alphaDash|length:6,20',
        'oldpassword' => 'require',
        'repassword' => 'require|confirm:password',
        'verify'   => 'require|alphaNum|max:4',
        'name'   => 'require',
        'phone'   => 'require|regex:/^1[3456789]\d{9}$/',
        'qid'   => 'require',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'username.require' => '用户名不能为空',
        'username.alphaNum' => '用户名只能为字母和数字',
        'username.max' => '用户名最多不能超过20个字符',
        'password.require' => '密码不能为空',
        'password.alphaDash' => '密码只能为字母和数字，下划线',
        'password.length' => '密码长度必须在6~20个字符之间',
        'password2.alphaDash' => '密码只能为字母和数字，下划线',
        'password2.length' => '密码长度必须在6~20个字符之间',
        'oldpassword.require' => '请输入原密码',
        'repassword.require' => '请输入新密码',
        'repassword.confirm' => '两次新密码不一致',
        'verify.require' => '验证码不能为空',
        'verify.alphaNum' => '验证码只能为字母和数字',
        'verify.max' => '验证码有误',
        'name.require' => '姓名不能为空',
        'phone.require' => '手机号不能为空',
        'phone.regex' => '手机号格式不正确',
        'qid.require' => '请选择管理员角色',

    ];

    protected $scene = [
        'login'  =>  ['username','password','verify'],
        'add' => ['username','name','phone','password','qid'],
        'edit' => ['username','name','phone','password2','qid'],
        'password' => ['oldpassword','password','repassword'],

    ];
}
